﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;

namespace Marmat.Forms
{
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(DevExpress.XtraEditors.LookUpEdit))]
    public partial class LookUpEdit : DropDownBox
    {
        public LookUpEdit()
        {

            // 此调用是设计器所必需的。
            this.InitializeComponent();

            // 在 InitializeComponent() 调用之后添加任何初始化。
            this.ShowModalButton = false;
            this.PopupControl = new LookUpEditForm();
            base.TextEditStyle = TextEditStyles.DisableTextEditor;
        }

        [DefaultValue(typeof(TextEditStyles), "DisableTextEditor")]
        public new TextEditStyles TextEditStyle
        {
            get
            {
                return base.TextEditStyle;
            }

            set
            {
                base.TextEditStyle = value;
            }
        }

        [DefaultValue(false)]
        public new bool ShowModalButton
        {
            get
            {
                return base.ShowModalButton;
            }

            set
            {
                base.ShowModalButton = value;
            }
        }

        public new object DataSource
        {
            get
            {
                return base.DataSource;
            }

            set
            {
                base.DataSource = value;
                ((LookUpEditForm)this.PopupControl).GridControl1.DataSource = value;
            }
        }

        /// <summary>
    /// 获取或设置 System.Windows.Forms.ComboBox 中当前选定的项。
    /// </summary>
    /// <value></value>
    /// <returns></returns>
    /// <remarks></remarks>
        public object SelectedItem
        {
            get
            {
                return this._SelectedItem;
            }

            set
            {
                if (!ReferenceEquals(this._SelectedItem, value))
                {
                    this._SelectedItem = value;
                    SelectionChangeCommitted?.Invoke(this, EventArgs.Empty);
                }
            }
        }

        private object _SelectedItem;

        /// <summary>
    /// 在所选项发生更改且更改显示在 System.Windows.Forms.ComboBox 中时发生。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <remarks></remarks>
        public event SelectionChangeCommittedEventHandler SelectionChangeCommitted;

        public delegate void SelectionChangeCommittedEventHandler(object sender, EventArgs e);

        public event SelectionEventHandler Selection;

        public delegate void SelectionEventHandler();
    }
}